<template>
  <div class="list-container">
    <div v-for="item in dataList"
         :key="item.name"
         class="list-item"
         @click="goDetail(item)">
      <div class="title">{{ item.title }}</div>
      <div class="time">时长：{{ item.time }}</div>
      <div class="brief">简介：{{ item.brief }}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PaperList',
  props: {
    list: {
      type: Array,
      default() {
        return []
      },
      required: true
    }
  },
  data() {
    return {
      dataList: this.list
    }
  },
  methods: {
    // 跳转到课程详情
    goDetail(detailInfo) {
      console.log(detailInfo)
      // this.$router.push({
      //   name: 'testPage',
      //   params: { id: detailInfo.title }
      // })
      const newTab = this.$router.resolve({
        name: 'testPage',
        params: { id: detailInfo.title }
      })
      window.open(newTab.href, '_blank')
    }
  }
}
</script>

<style lang="scss" scoped>
// 列表容器
.list-container {
  height: 100%;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  // 每一项
  .list-item {
    // 底部有适配该item的hover
    width: 200px;
    height: 200px;
    margin: 0px 5px 10px;
    padding: 10px;
    border: 1px solid #f0f0f0;
    border-radius: 8px;
    box-sizing: border-box;
    cursor: pointer;
    overflow: hidden;
    transition: 0.3s;
    // 标题、时长、简介
    .title,
    .time,
    .brief {
      margin-bottom: 10px;
    }
    .time,
    .brief {
      font-size: 13px;
      color: #999999;
    }
    .title {
      width: 190px;
      font-weight: 600;
      padding: 5px 0px 10px;
      border-bottom: 1px solid #ebeef5;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .brief {
      width: 190px;
      line-height: 19px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 6;
      -o-text-overflow: ellipsis;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}
// 只适配支持hover的设备
@media (any-hover: hover) {
  .list-container .list-item:hover {
    box-shadow: rgba(0, 0, 0, 0.2) 0px 5px 10px;
  }
}
</style>
